<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card
      :bordered="false"
      style="over-flow:scroll"
    >
      <div>
        <a-row>
          <a-col
            :md="24"
            :sm="19"
          >
            <div class="table-operator">
              <a-row>
                <a-col
                  :md="24"
                  :sm="24"
                >
                  <a-button
                    v-btnPermission="'pm_015_add_01'"
                    type="primary"
                    @click="goAdd('add')"
                  >
                    新增推荐
                  </a-button>
                </a-col>
              </a-row>
            </div>
            <div class="pub-table-select-count">
              <a-icon
                type="info-circle"
                theme="twoTone"
              />
              <span style="margin-right: 12px">
                总推荐数：<span class="totalNum">{{ total.recommendTotal || 0 }} 个</span> | 审核通过：<span class="totalNum">{{ total.passAudit || 0 }} 个</span> | 审核中：<span
                  class="totalNum">{{ total.inReview || 0 }} 个</span>
                | 审核不通过：<span class="totalNum">{{ total.notApproved || 0 }} 个 </span>
              </span>
            </div>

            <list-table
              ref="table"
              size="default"
              row-key="id"
              :columns="columns"
              :request="loadData"
              :alert="true"
              show-size-changer
              show-quick-jumper
              show-pagination="auto"
            >
              <span
                slot="serial"
                slot-scope="text, record, index"
              >{{ index + 1 }}</span>
              <span
                slot="subcontractorTypes"
                slot-scope="text"
              >
                <ellipsis
                  :length="30"
                  tooltip
                >{{ text }}</ellipsis>
              </span>
              <span
                slot="cooperation"
                slot-scope="text"
              >
                <ellipsis
                  :length="20"
                  tooltip
                >{{ text }}</ellipsis>
              </span>
              <span
                slot="action"
                slot-scope="text, record"
              >
                <MoreButton>
                  <a
                    v-btnPermission="'pm_015_loo_02'"
                    @click="handleSub(record, 'view')"
                  >查看</a>
                  <a-divider
                    v-if="record.statusCode == '0' || record.statusCode == '3'"
                    v-btnPermission="'pm_015_edi_03'"
                    type="vertical"
                  />
                  <a
                    v-if="record.statusCode == '0' || record.statusCode == '3'"
                    v-btnPermission="'pm_015_edi_03'"
                    @click="handleEdit(record, 'edit')"
                  >编辑</a>
                  <a-divider
                    v-if="record.statusCode == '1' || record.statusCode == '2' || record.statusCode == '3'"
                    v-btnPermission="'pm_015_moi_04'"
                    type="vertical"
                  />
                  <a
                    v-if="record.statusCode == '1' || record.statusCode == '2' || record.statusCode == '3'"
                    v-btnPermission="'pm_015_moi_04'"
                    @click="handleApproveDetail(record)"
                  >审批信息</a>
                </MoreButton>
              </span>
            </list-table>
          </a-col>
        </a-row>
      </div>
    </a-card>

    <a-modal
      v-if="visible"
      :title="title"
      :visible="true"
      :confirm-loading="confirmLoading"
      :ok-button-props="{ props: { disabled: type === 'view' } }"
      width="60%"
      ok-text="提交审核"
      @cancel="visible = false"
      @ok="handleOk"
    >
      <title-name title="推荐分包商信息" />
      <!-- 查看并审核通过时，才可打印 -->
      <print-button
        v-if="type == 'view' && isPrint"
        :print-content="htmlData"
        :before-print-fn="getSubDoc"
        style="margin-bottom: 10px;"
      />

      <a-form-model
        ref="ruleForm"
        :model="form"
        :rules="type == 'view' ? {} : rules"
        :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
      >
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="推荐分包商"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              prop="recommendSubcontractors"
            >
              <BaseInput
                v-model="form.recommendSubcontractors"
                :disabled="type == 'view'"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="分包商类型"
              :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
              :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
              prop="list"
            >
              <a-tree-select
                v-model="form.list"
                tree-node-filter-prop="title"
                :disabled="type == 'view'"
                style="width: 100%;"
                :replace-fields="{ children: 'children', key: 'id', value: 'id', title: 'name' }"
                :dropdown-style="{ maxHeight: '300px', overflow: 'auto' }"
                :tree-data="invesList"
                multiple
                :filter-tree-node="fillterFUN"
                placeholder="请选择/搜索"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <!--岗位为项目部时项目必填 为公司或者分公司项目非必填-->
          <a-col
            v-if="branchLevel == true || companyLevel == true"
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="推荐承诺："
              style="display:flex"
              :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
              :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
              :prop="form.branchCompanyId ? 'cooperation' : 'branchCompanyId'"
            >
              <div style="display:flex;justify-content: space-between;align-items: center;margin-bottom:24px">
                本人推荐该公司参加
                <a-select
                  v-model="form.branchCompanyId"
                  placeholder="请选择"
                  class="selectbranch"
                  :disabled="type == 'view'"
                  @change="changeBranchCompany"
                >
                  <a-spin
                    v-if="loading"
                    slot="notFoundContent"
                    size="small"
                  />
                  <a-select-option
                    v-for="item in companyList"
                    :key="item.orgId"
                    :value="item.orgId"
                  >
                    {{ item.orgName }}
                  </a-select-option>
                </a-select>
                单位
                <a-select
                  v-if="isShow"
                  v-model="form.projectId"
                  class="selectProject unRequired"
                  placeholder="请选择"
                  show-search
                  :filter-option="filterOption"
                >
                  <a-spin
                    v-if="loading"
                    slot="notFoundContent"
                    size="small"
                  />
                  <a-select-option
                    v-for="item in projectList"
                    :key="item.projectId"
                    :value="item.projectId"
                  >
                    {{ item.projectName }}
                  </a-select-option>
                </a-select>
                <BaseInput
                  v-if="isShowProject"
                  v-model="form.project"
                  :disabled="type == 'view'"
                  style="width: 35%"
                />
                项目
              </div>
              <a-input
                v-model="form.cooperation"
                :max-length="30"
                class="cooperation"
                :disabled="type == 'view'"
                placeholder="请输入"
                style="margin-right: 10px;width:35%"
                @change="$refs.ruleForm.validateField('cooperation')"
              />
              (标的物品名） 招标/议标采购。如果出现供货（或工程）质量、供货（或工程）延期、冒牌、弄虚作假.....等有关问题，本人协调处理。
            </a-form-model-item>
          </a-col>

          <!-- 为项目部登录时 -->
          <a-col
            v-if="projectLevel == true"
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="推荐承诺："
              style="display:flex"
              :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
              :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
              :prop="form.projectId ? 'cooperation' : 'projectId'"
            >
              <div style="display:flex;justify-content: space-between;align-items: center;margin-bottom:24px">
                本人推荐该公司参加
                <a-select
                  v-model="form.branchCompanyId"
                  placeholder="请选择"
                  class="selectbranch"
                  :disabled="type == 'view'"
                  @change="changeBranchCompany"
                >
                  <a-spin
                    v-if="loading"
                    slot="notFoundContent"
                    size="small"
                  />
                  <a-select-option
                    v-for="item in companyList"
                    :key="item.orgId"
                    :value="item.orgId"
                  >
                    {{ item.orgName }}
                  </a-select-option>
                </a-select>
                单位
                <a-select
                  v-if="isShow"
                  v-model="form.projectId"
                  class="selectProject"
                  placeholder="请选择"
                  show-search
                  :filter-option="filterOption"
                  @change="$refs.ruleForm.validateField('projectId')"
                >
                  <a-spin
                    v-if="loading"
                    slot="notFoundContent"
                    size="small"
                  />
                  <a-select-option
                    v-for="item in projectList"
                    :key="item.projectId"
                    :value="item.projectId"
                  >
                    {{ item.projectName }}
                  </a-select-option>
                </a-select>
                <BaseInput
                  v-if="isShowProject"
                  v-model="form.project"
                  :disabled="type == 'view'"
                  style="width: 35%"
                />
                项目
              </div>
              <a-input
                v-model="form.cooperation"
                :max-length="30"
                class="cooperation"
                :disabled="type == 'view'"
                placeholder="请输入"
                style="margin-right: 10px;width:35%"
                @change="$refs.ruleForm.validateField('cooperation')"
              />
              (标的物品名） 招标/议标采购。如果出现供货（或工程）质量、供货（或工程）延期、冒牌、弄虚作假.....等有关问题，本人协调处理。
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col>
            <a-form-model-item
              label="推荐理由："
              style="display:flex"
              :label-col="{ lg: { span: 3 }, sm: { span: 3 } }"
              :wrapper-col="{ lg: { span: 21 }, sm: { span: 21 } }"
              prop="recommendInformation"
            >
              <BaseTextarea
                v-model="form.recommendInformation"
                :disabled="type == 'view'"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <!-- <title-name title="推荐人信息" /> -->
      <a-form-model :model="form.recommendInfo">
        <a-row :gutter="24">
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="推荐人："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.referrer"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="年龄："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.age"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="身份证号："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.idNum"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="政治面貌："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.politicalFace"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="单位："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.unitName"
                :title="form.recommendInfo.unitName"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="职位："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.position"
                :title="form.recommendInfo.position"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="联系方式："
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="form.recommendInfo.tel"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>
    <!-- 审批详情 -->
    <ApprovalDetails
      :title="'审批详情'"
      :business-id="businessId"
      :visible="visibleApprove"
      @cancel="visibleApprove = false"
      @confirm="visibleApprove = false"
    />
    <!-- 选择审批人 -->
    <selectApprover
      :business-id="businessId"
      :process-config="setProcessConfig"
      :is-close-upper="false"
      @close="visible = false"
    />
    <!-- 选择审批人 -->
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { auditStatus } from '@/components/constant'
import { getInvestigateType } from '@/api/subcontractors/subcontractors'
import { getSubcontractorsList, addSubcontractors, editSubcontractors, subcontractorsTotal, getSubDetails, istheSameName, getSubDoc } from '@/api/subcontractors'
import { getUsersDetail, getCurrentUserBranchCom2, getAllBranchCompany } from '@/api/commons'
import { getOrgsTree } from '@/api/subassembly/TreeSelectOrganization'
import { getProject } from '@/api/themeChoose/themeChoose'
import { getProjectsList } from '@/api/project/projects'
import printButton from '@/components/BasePrintButton'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司选择框
import OrgTreeSelect from '@/components/OrgTreeSelect'
import ApprovalDetails from '@/components/approvalDetails'
import { getAuditProject } from '@/api/themeChoose/themeChoose'
import SelectProject from '@/components/Select/SelectProject'
import api from '@/api/project/typeMaintenance'

const columns = [
  {
    title: '序号',
    width: 65,
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '推荐分包商',
    width: 200,
    dataIndex: 'recommendSubcontractors'
  },
  {
    title: '分包商类型',
    dataIndex: 'subcontractorTypes',
    width: 200,
    scopedSlots: { customRender: 'subcontractorTypes' }
  },
  {
    title: '推荐人',
    width: 200,
    dataIndex: 'recommend'
  },
  {
    title: '分公司',
    width: 200,
    dataIndex: 'branchCompany'
  },
  {
    title: '推荐项目',
    width: 300,
    dataIndex: 'recommendProject'
  },
  {
    title: '合作事项',
    dataIndex: 'cooperation',
    width: 200,
    scopedSlots: { customRender: 'cooperation' }
  },
  {
    title: '状态 ',
    width: 200,
    dataIndex: 'statusName'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 150,
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    printButton,
    ApprovalDetails,
    Ellipsis
  },
  data() {
    this.columns = columns
    this.auditStatus = auditStatus
    return {
      searchArr: [
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '分公司',
        //   valueKey: 'branchCompanyId',
        //   type: SelectSubCompany
        // },
        // {
        //   name: '推荐项目',
        //   type: SelectProject,
        //   valueKey: 'projectId'
        // },
        {
          name: '推荐分包商',
          value: 'recommendSubcontractors',
          type: 'input'
        },
        {
          name: '分包商类型',
          value: 'typeId',
          type: 'tree-select',
          attrs: {
            allowClear: true,
            replaceFields: { children: 'children', title: 'name', key: 'id', value: 'id' }
          },
          data: []
        },
        {
          name: '推荐人',
          value: 'recommend',
          type: 'input'
        },

        {
          name: '合作事项',
          value: 'cooperation',
          type: 'input'
        },
        {
          name: '状态',
          value: 'status',
          type: 'select',
          data: [
            // 取消待提交审核状态
            // {
            //   value: '0',
            //   label: '待提交审核'
            // },
            {
              value: '1',
              label: '审核中'
            },
            {
              value: '2',
              label: '审核通过'
            },
            {
              value: '3',
              label: '审核不通过'
            }
          ]
        }
      ],
      isPrint: false,
      htmlData: '',
      id: '',

      searchValue: '',
      isShow: true,
      isShowProject: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getSubcontractorsList(requestParameters).then((res) => {
          return res
        })
      },
      selectedRowKeys: '',
      selectedRows: '',
      disabled: false,
      loading: false,
      visibleApprove: false,
      invesList: [],
      projectList: [],
      confirmLoading: false,

      projectLevel: false, //是否为项目部层级
      branchLevel: false, //是否为分公司层级
      companyLevel: false, //是否为公司层级

      form: {
        list: null,
        recommendInfo: {
          recommendInfo: '',
          age: '',
          idNum: '',
          politicalFace: '',
          unitName: '',
          tel: '',
          position: ''
        },
        projectId: ''
      },
      value: '',
      type: [],
      title: '',
      companyList: [],
      visible: false,
      recommendInfo: {},
      advanced: false,
      total: {},
      userId: '',
      rules: {
        recommendSubcontractors: [{ required: true, message: '请填写推荐分包商', trigger: 'change' }],
        list: [{ required: true, message: '请选择分包商类型', trigger: 'change' }],
        branchCompanyId: [{ required: true, message: '请选择单位', trigger: 'change' }],
        projectId: [{ required: true, message: '请选择项目', trigger: 'change' }],
        cooperation: [{ required: true, message: '请输入物品名', trigger: 'change' }],
        recommendInformation: [{ required: true, message: '请填写推荐理由', trigger: 'change' }]
      },
      // 流程配置
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      // 业务id
      businessId: null
    }
  },
  async created() {
    //获取通过获取流程配置值
    this.processConfig = await this.$getConfigFn('labor_subcontract_recommend')
    const obj = JSON.parse(sessionStorage.getItem('ycloud-user_info')).currentPost
    this.branchLevel = obj.code == 'BC' //分公司级
    this.companyLevel = obj.code == 'CO' //公司级
    this.projectLevel = obj.code == 'PD' //项目级
    this.userId = JSON.parse(sessionStorage.getItem('ycloud-user_info')).id
    this.subcontractorsTotal()
    this.getInvestigateType()
    this.getTreeData()
  },
  mounted() {
    // 设置分包商类型输入框readonly
  },
  methods: {
    async getTreeData() {
      let res = await api.labelTreeList()
      if (res.code === 200) {
        this.searchArr[2].data = this.allEnabledDigui(res.data)
      }
    },
    allEnabledDigui(list) {
      let r = []
      list.map((v) => {
        v.disabled = false
        if (v.children && v.children.length) {
          v.children = this.allEnabledDigui(v.children)
        }
        r.push(v)
      })
      return r
    },
    getSubDoc() {
      let that = this
      return new Promise((resolve, reject) => {
        let data = { templateCode: 'CSCEC8XN-SU-B11002', businessId: this.id }
        getSubDoc(data)
          .then((res) => {
            if (res.code == 200 || res.data.code === 200) {
              resolve(res.data.content)
            }
          })
          .catch((e) => {
            that.$message.error(e)
          })
          .finally(() => {
            resolve()
          })
      })
    },

    getOrgsTree() {
      this.loading = true
      getCurrentUserBranchCom2({ tagCodes: ['BC'] }).then((res) => {
        this.companyList = res.data
        this.loading = false
      })
    },

    async changeBranchCompany(value) {
      this.loading = true
      this.$refs.ruleForm && this.$refs.ruleForm.validateField('branchCompanyId')
      if (value) {
        this.$set(this.form, 'projectId', '')
        let res = await getAuditProject({ branchComIds: [value], auditStatus: 2 }).catch(() => {
          this.loading = false
        })
        this.projectList = res.data
        this.loading = false
      }
    },

    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    // handleChangeProject(){
    //   this.$refs.ruleForm.validateField('projectId')
    // },
    handleApproveDetail(record) {
      this.visibleApprove = true
      this.businessId = record.id
    },
    getUsersDetail() {
      getUsersDetail({ userId: this.userId }).then((res) => {
        this.form.recommendInfo.referrer = res.data.name
        this.form.recommendInfo.age = res.data.age
        this.form.recommendInfo.idNum = res.data.idCard
        this.form.recommendInfo.politicalFace = res.data.politicalFace
        const company = res.data.levels
        const lists = []
        company.forEach((item) => {
          lists.push(item.name)
        })
        this.form.recommendInfo.unitName = lists.join(',')
        this.form.recommendInfo.tel = res.data.phoneNum
        const arr = res.data.posts
        const list = []
        arr.forEach((item) => {
          list.push(item.name)
        })
        this.form.recommendInfo.position = list.join(',')
        this.recommendInfo = res.data
      })
    },
    subcontractorsTotal() {
      subcontractorsTotal(this.queryParam).then((res) => {
        this.total = res.data
      })
    },
    // 分包商类型
    getInvestigateType() {
      getInvestigateType({ enabledCode: '1' }).then((res) => {
        this.invesList = this.digui(res.data)
      })
    },
    digui(list) {
      let r = []
      list.map((v) => {
        if (!v.disabled) {
          let r2 = this.$clone(v)
          if (v.children && v.children.length) {
            let list = this.digui(v.children)
            if (list.length) {
              r2.children = list
              r2.disabled = true
            } else {
              r2.children = []
              r2.disabled = false
            }
          } else {
            r2.disabled = false
          }
          r.push(r2)
        }
      })
      return r
    },
    fillterFUN(searchVal, treeNode) {
      return treeNode.data.props.name.includes(searchVal)
    },
    addEmpty() {},
    onSelectChange(selectedRowKeys, selectedRows) {
      console.log(selectedRowKeys)
      console.log(selectedRows)
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    search(values) {
      console.log(values)
      this.queryParam = values
      this.$refs.table.refresh(true)
      this.subcontractorsTotal()
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    goAdd(type) {
      this.confirmLoading = false
      this.getOrgsTree()
      this.form = {
        recommendInfo: {}
      }
      this.visible = true
      this.isShow = true
      this.isShowProject = false
      this.title = '新增分包商推荐'
      this.type = type
      this.projectList = []

      this.getInvestigateType()
      getUsersDetail({ userId: this.userId }).then((res) => {
        this.form.recommendInfo.referrer = res.data.name
        this.form.recommendInfo.age = res.data.age
        this.form.recommendInfo.idNum = res.data.idCard
        this.form.recommendInfo.politicalFace = res.data.politicalFace
        const company = res.data.levels
        const lists = []
        company.forEach((item) => {
          lists.push(item.name)
        })
        this.form.recommendInfo.unitName = lists.join(',')
        this.form.recommendInfo.tel = res.data.phoneNum
        const arr = res.data.posts
        const list = []
        arr.forEach((item) => {
          list.push(item.name)
        })
        this.form.recommendInfo.position = list.join(',')
        this.recommendInfo = res.data
      })
    },
    handleSub(record, type) {
      // this.confirmLoading = true
      this.id = record.id
      this.isPrint = record.statusCode === '2'
      this.getOrgsTree()
      this.visible = true
      this.title = '查看分包商推荐'
      this.isShow = false
      this.isShowProject = true
      // this.form = record
      this.getInvestigateType()
      getSubDetails({ id: record.id }).then((res) => {
        this.form = (res.data && { ...res.data }) || {}
        this.$nextTick(() => {
          this.form.projectId = res.data.projectId
        })
        if (this.form.branchCompanyId) {
          this.changeBranchCompany(this.form.branchCompanyId, true)
        }

        let list = this.form.list
        if (list) {
          this.form.list = list.map((item) => item.id)
        }
      })
      this.form.recommendInfo = this.recommendInfo
      this.type = type
    },
    handleEdit(record, type) {
      let that = this
      that.confirmLoading = false
      that.getOrgsTree()
      that.visible = true
      that.isShow = true
      that.isShowProject = false
      that.title = '编辑分包商推荐'
      // this.form = record
      that.getInvestigateType()
      if (record.branchCompanyId) {
        that.changeBranchCompany(record.branchCompanyId)
      }
      getSubDetails({ id: record.id }).then((res) => {
        that.form = (res.data && { ...res.data }) || {}

        if (that.projectList.length > 0) {
          const target = that.projectList.find((item) => (item.projectId = res.data.projectId))

          if (target == null || target == undefined) {
            that.form.projectId = ''
          } else {
            that.$nextTick(() => {
              that.form.projectId = res.data.projectId
            })
          }
        } else {
          that.$nextTick(() => {
            that.form.projectId = res.data.projectId
          })
        }

        let list = []
        that.form.list.forEach((item) => {
          list.push(item.id)
        })
        let lists = []
        that.form.list.forEach((item) => {
          lists.push(item.id)
        })
        console.log(list)
        that.form.list = list
        that.form.lists = lists
      })
      that.form.recommendInfo = that.recommendInfo
      that.type = type
      // if(this.form.branchCompanyId){
      that.changeBranchCompany(that.form.branchCompanyId, true)
      // }
    },
    handleOk() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.confirmLoading = true
          console.log(this.form)
          if (this.form.id) {
            istheSameName({
              recommendSubcontractors: this.form.recommendSubcontractors,
              branchCompanyId: this.form.branchCompanyId,
              addOrEdit: 1
            })
              .then((res) => {
                if (res.data == '0') {
                   if(this.processConfig*1 === 4){
                    this.visible = false
                  }
                  let obj = []
                  this.form.list.forEach((item) => {
                    obj.push({ id: item })
                  })
                  this.form.list = obj
                  editSubcontractors(this.form)
                    .then((res) => {
                      if (res.code == 200) {
                        this.confirmLoading = false
                        this.$message.success('提交成功')
                        // this.$refs.table.refresh(true)
                        this.businessId = res.data.id
                        this.setProcessConfig = this.processConfig
                           if(this.processConfig*1 === 4){
                           this.$refs.table.refresh(true)
                        }else{
                           this.businessId = res.data.id
                           this.setProcessConfig = this.processConfig
                          this.$refs.table.refresh(true)
                        }
                      }
                    })
                    .catch(() => (this.visible = false))
                } else {
                  this.confirmLoading = false
                  this.$message.error('该分公司下已经存在该分包商推荐')
                  return false
                }
              })
              .catch(() => (this.visible = false))
          } else {
            istheSameName({
              recommendSubcontractors: this.form.recommendSubcontractors,
              branchCompanyId: this.form.branchCompanyId,
              addOrEdit: 0
            })
              .then((res) => {
                console.log(res.data)
                if (res.data == '0') {
                  if(this.processConfig*1 === 4){
                    this.visible = false
                  }
                  // this.visible = false
                  let obj = []
                  this.form.list.forEach((item) => {
                    obj.push({ id: item })
                  })
                  this.form.list = obj
                  addSubcontractors(this.form)
                    .then((res) => {
                      if (res.code == 200) {
                        this.confirmLoading = false
                        this.$message.success('提交成功')
                        // this.$refs.table.refresh(true)
                           if(this.processConfig*1 === 4){
                           this.$refs.table.refresh(true)
                        }else{
                           this.businessId = res.data.id
                           this.setProcessConfig = this.processConfig
                           this.$refs.table.refresh(true)
                        }
                        // this.$refs.table.refresh(true)
                        this.subcontractorsTotal()
                      }
                    })
                    .catch(() => (this.visible = false))
                } else {
                  this.confirmLoading = false
                  this.$message.error('该分公司下已经存在该分包商推荐')
                  return false
                }
              })
              .catch(() => (this.visible = false))
          }
        }
      })
    }
    // handleCancel(){
    // // this.confirmLoading= true
    // this.visible = false
    // this.$refs.ruleForm.clearValidate()
    // }
  }
}
</script>

<style lang="less" scoped>
.unRequired {
  /deep/ .ant-select-selection {
    border-color: #d9d9d9 !important;
    background-color: #fff !important;
  }
}

.input {
  width: 100%;
}

.total {
  display: flex;
}

.total div {
  padding: 0 5px;
}

.selectbranch,
.cooperation,
.selectProject {
  width: 35% !important;
}

/deep/ .ant-select-tree li span.ant-select-tree-switcher,
.ant-select-tree li span.ant-select-tree-iconEle {
  line-height: 12px !important;
}
</style>
